package be.jprojects.tests.filter;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class FilterItemPanel extends JPanel {
	private JLabel iconLabel, titleLabel, infoLabel;
	private ImageIcon imageIcon=new ImageIcon("/Resources/null.png");
	
	public FilterItemPanel() {
		super.setLayout(new GridBagLayout());
		iconLabel = new JLabel();
		iconLabel.setPreferredSize(new Dimension(48,48));
		iconLabel.setIcon(imageIcon);
		addWithGridBag(iconLabel, this, 0, 0, 1, 2, GridBagConstraints.WEST, GridBagConstraints.BOTH, 0, 0);
		titleLabel = new JLabel("title");
        Font titleFont = titleLabel.getFont().deriveFont (Font.BOLD, titleLabel.getFont().getSize()); 
        titleLabel.setFont (titleFont); 
        
		addWithGridBag(titleLabel, this, 1, 0, 2, 1, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, 1, 0);
		infoLabel = new JLabel("info");
        Font infoFont =	infoLabel.getFont().deriveFont (Font.PLAIN, titleLabel.getFont().getSize()-2); 
		infoLabel.setFont (infoFont); 
		addWithGridBag(infoLabel, this, 2, 1, 1, 1,	GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, 1, 0);
		setMinimumSize(new Dimension(200,50));
	}
	
	private void addWithGridBag(Component comp, Container cont, int x, int y,
			int width, int height, int anchor, int fill, int weightx,
			int weighty) {
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = width;
		gbc.gridheight = height;
		gbc.anchor = anchor;
		gbc.fill = fill;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
		cont.add(comp, gbc);
	}

	public void setColors(Color foreground, Color background) {
		setForeground(foreground);
		setBackground(background);
		titleLabel.setForeground(foreground);
		titleLabel.setBackground(background);
		infoLabel.setForeground(foreground);
		infoLabel.setBackground(background);
	}
	
	public void setTitle(String title) {
		titleLabel.setText(title);
	}
	public void setInfo(String info) {
		infoLabel.setText(info);
	}
	public void setIcon(ImageIcon icon) {
		imageIcon.setImage( icon.getImage() );
	}
	
	


}
